package com.danny.login

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.danny.provider.RouterPath
import kotlinx.android.synthetic.main.activity_login.*
import org.jetbrains.anko.toast

//@Route(path = "/account/login")
@Route(path = RouterPath.Login.PATH_LOGIN)
class LoginActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
        AccountUtils.userInfo = UserInfo("10086","Danny")
        updateLoginState()
    }

    fun exit(view: View) {
        AccountUtils.userInfo = null
        updateLoginState()
    }
    @SuppressLint("SetTextI18n")
    private fun updateLoginState(){
        tv_login_state.text = "这里是登录界面：${if (AccountUtils.userInfo == null) "未登录" else AccountUtils.userInfo!!.userName}"
    }

    fun login(view: View) {
        AccountUtils.userInfo = UserInfo("10086","Kiki")
        updateLoginState()
    }

    fun loginShare(view: View) {
        ARouter.getInstance()
                .build(RouterPath.Share.PATH_SHARE)
                .withString("share_content","分享数据到微博")
                .navigation(this,object: NavigationCallback{
                    override fun onLost(postcard: Postcard?) {
                    }

                    override fun onFound(postcard: Postcard?) {
                    }

                    override fun onArrival(postcard: Postcard?) {
                    }

                    override fun onInterrupt(postcard: Postcard?) {
                        runOnUiThread { toast("请先登录") }
                    }
                })
    }
}
